#include "open_file_dialog.h"

void OpenFileDialog_init(OpenFileDialog* dialog, HWND hwndOwner, LPCTSTR lpstrFilter, 
	LPTSTR lpstrTitle, LPCTSTR lpstrDefExt)
{
	OPENFILENAME* pofn = &dialog->openFileName;

	ZeroMemory(pofn, sizeof(*pofn));
	pofn->lStructSize = sizeof(OPENFILENAME);
	pofn->hwndOwner = hwndOwner;
	pofn->hInstance = NULL;
	pofn->lpstrFilter = lpstrFilter;
	pofn->lpstrCustomFilter = NULL;
	pofn->nMaxCustFilter = 0;
	pofn->nFilterIndex = 0;
	pofn->lpstrFile = dialog->szFile;  // set in GetOpenFileName function
	pofn->nMaxFile = MAX_PATH;
	pofn->lpstrFileTitle = dialog->szFileTitle;  // set in GetOpenFileName function
	pofn->nMaxFileTitle = MAX_PATH;
	pofn->lpstrInitialDir = NULL;
	pofn->lpstrTitle = lpstrTitle;
	pofn->Flags = OFN_FILEMUSTEXIST;
	pofn->nFileOffset = 0;
	pofn->nFileExtension = 0;
	pofn->lpstrDefExt = lpstrDefExt;
	pofn->lCustData = 0;
	pofn->lpfnHook = NULL;
	pofn->lpTemplateName = NULL;

	dialog->szFile[0] = '\0';
	dialog->szFileTitle[0] = '\0';
}

BOOL OpenFileDialog_show(OpenFileDialog* dialog)
{
	return GetOpenFileName(&dialog->openFileName);
}
